# https://github.com/ankitects/anki/blob/main/qt/tools/genhooks_gui.py
from aqt import mw
from aqt.editor import Editor
from aqt.reviewer import Reviewer

# ===== Web Content
def on_webview_will_set_content(web_content, context):
  if isinstance(context, Editor):
    # web_content.body += editor_html
    pass
  elif isinstance(context, Reviewer):
    # web_content.body += reviewer_html
    pass

  addon_package = mw.addonManager.addonFromModule(__name__)
  web_content.css.append(f"/_addons/{addon_package}/web/my-addon.css")
  web_content.js.append(f"/_addons/{addon_package}/web/my-addon.js")

def on_main_window_did_init():
    """Add our custom user styles to the editor HTML
    Need to delay this to avoid interferences with other add-ons that might
    potentially overwrite editor HTML"""
    from aqt.gui_hooks import webview_will_set_content

    webview_will_set_content.append(on_webview_will_set_content)

# ===== export injections
def setup_webview_injections():
  from aqt.gui_hooks import main_window_did_init

  main_window_did_init.append(on_main_window_did_init)
  mw.addonManager.setWebExports(__name__, r"web/.*")